package gui;

import java.awt.GridBagConstraints;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class Block extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//-------------------------------------------------------- GUI vars
	protected JFrame controlWindow; 
	protected String title;

	//-------------------------------------------------------- mvc vars
	protected ArrayList<JPanel> views = new ArrayList<JPanel>();
	
	//-------------------------------------------------------- constructor

	public Block(String title) {
		this.title = title;
		
		//this.setLayout(new BoxLayout(this, 3));
		//setLayout(new GridLayout());
		
	}

	//-------------------------------------------------------- control windows
	//-------------------------------------------------------- 
	
	/** chiamata internamente, inizializza il pannello JFrame di constrollo 
	 *  subclassare e override per mettere slider, checkbox, etc*/
	protected void initControls() {
		controlWindow = new JFrame(title + " controls");
	}

	/**chiamato da BlockFactory!! pack del pannello*/
	public Block init()  {
		initControls();
		
		controlWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		controlWindow.pack();
		controlWindow.setVisible(true);
		return this;
	}
	/**chiamato da BlockFactory!! dispose del pannello*/
	public Block dispose() {
		controlWindow.dispose();
		controlWindow.setVisible(false);
		return this;
	}
	

	//-------------------------------------------------------- publics
	//-------------------------------------------------------- view controls
	public void addView(JPanel v) {
		views.add(v);
		add(v);
	}
	
	public void addView(JPanel v, GridBagConstraints c) {
		views.add(v);
		add(v, c);
	}


}